package com.study.hot.jetpack.room.test_address.repository

import android.content.Context
import androidx.room.Room
import com.study.hot.jetpack.room.test_address.db.AddressDao
import com.study.hot.jetpack.room.test_address.db.AddressDatabase

/**
 * <pre>
 *     author : fauks
 *     time   : 2020/03/25
 *     desc   :
 * </pre>
 */
class AddressRepository private constructor(val context: Context) {
    companion object {
        fun newInstance(context: Context) = AddressRepository(context)
    }

    private val addressDatabase: AddressDatabase by lazy {
        Room.databaseBuilder(context, AddressDatabase::class.java, "address_db").allowMainThreadQueries().build()
    }
    val addressDao: AddressDao by lazy {
        addressDatabase.getAddressDao()
    }
}